/*
 *  arch/arm/include/asm/tlbflush.h
 *
 *  Copyright (C) 1999-2003 Russell King
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 */
#ifndef _ASMARM_TLBFLUSH_H
#define _ASMARM_TLBFLUSH_H

// #include <asm/system.h>

#define isb() __asm__ __volatile__ ("isb" : : : "memory")
#define dsb() __asm__ __volatile__ ("dsb" : : : "memory")

static inline void local_flush_tlb_all(void)
{
	const int zero = 0;
	// const unsigned int __tlb_flag = __cpu_tlb_flags;

	// if (tlb_flag(TLB_WB))
	if (1)
		dsb();

	// if (tlb_flag(TLB_V3_FULL))
	// 	asm("mcr p15, 0, %0, c6, c0, 0" : : "r" (zero) : "cc");
	// if (tlb_flag(TLB_V4_U_FULL | TLB_V6_U_FULL))
	if (1)
		asm("mcr p15, 0, %0, c8, c7, 0" : : "r" (zero) : "cc");
	// if (tlb_flag(TLB_V4_D_FULL | TLB_V6_D_FULL))
		// asm("mcr p15, 0, %0, c8, c6, 0" : : "r" (zero) : "cc");
	// if (tlb_flag(TLB_V4_I_FULL | TLB_V6_I_FULL))
	// 	asm("mcr p15, 0, %0, c8, c5, 0" : : "r" (zero) : "cc");
	// if (tlb_flag(TLB_V7_UIS_FULL))
	// 	asm("mcr p15, 0, %0, c8, c3, 0" : : "r" (zero) : "cc");

	// if (tlb_flag(TLB_BTB)) {
	if (1) {
		/* flush the branch target cache */
		asm("mcr p15, 0, %0, c7, c5, 6" : : "r" (zero) : "cc");
		dsb();
		isb();
	}
}

static inline void flush_pmd_entry(pmd_t *pmd)
{
	// const unsigned int __tlb_flag = __cpu_tlb_flags;

	// if (tlb_flag(TLB_DCLEAN))
	if (1)
		asm("mcr	p15, 0, %0, c7, c10, 1	@ flush_pmd"
			: : "r" (pmd) : "cc");

	// if (tlb_flag(TLB_L2CLEAN_FR))
	// 	asm("mcr	p15, 1, %0, c15, c9, 1  @ L2 flush_pmd"
	// 		: : "r" (pmd) : "cc");

	// if (tlb_flag(TLB_WB))
	if (1)
		// dsb();
		__asm__ __volatile__ ("dsb" : : : "memory");
}

static inline void clean_pmd_entry(pmd_t *pmd)
{
	// const unsigned int __tlb_flag = __cpu_tlb_flags;

	// if (tlb_flag(TLB_DCLEAN))
	if (1)
		asm("mcr	p15, 0, %0, c7, c10, 1	@ flush_pmd"
			: : "r" (pmd) : "cc");

	// if (tlb_flag(TLB_L2CLEAN_FR))
	// 	asm("mcr	p15, 1, %0, c15, c9, 1  @ L2 flush_pmd"
	// 		: : "r" (pmd) : "cc");
}

#define flush_tlb_all		local_flush_tlb_all

#endif
